<script>
	import {
		getOpenid, //获取openid
	} from '@/request/api.js'
	export default {
		onLaunch: function() {
			console.log('App Launch')
			console.log('先看有没有openid')
			console.log(uni.getStorageSync('openid'))
			if (uni.getStorageSync('openid')) {
				console.log('不用再去获取openid了')
				return
			}
			let openId = ''
			console.log('通过腾讯接口获取openid')
			uni.login({
				provider: 'weixin',
				success: res => {
					//code值(5分钟失效)
					let code = res.code;
					uni.setStorageSync('codeGetOpenid', code)
					console.log('获取code---用于请求后端接口-获取openid')
					console.log(code)
					// //小程序appid
					// let appid = 'wxb4a2f0381c8e1cb8'; //小程序id
					// //小程序secret
					// let secret = '770987c23faafd7cafed3c380b0039ec'; //密钥
					// //wx接口路径
					// let url = 'https://api.weixin.qq.com/sns/jscode2session';
					// uni.request({
					// 	url: url, // 请求路径
					// 	data: {
					// 		appid: appid,
					// 		secret: secret,
					// 		js_code: code,
					// 		grant_type: 'authorization_code'
					// 	}, // 请求体
					// 	method: 'GET', //请求方法,
					// 	header: {}, //请求头
					// 	success: result => {
					// 		//响应成功
					// 		//这里就获取到了openid了
					// 		// openId = result.data.openid
					// 		// uni.showToast({
					// 		// 	icon: 'none',
					// 		// 	title: result.errMsg
					// 		// })
					// 		console.log('获取openid')
					// 		console.log(result)
					// 		uni.setStorageSync('openid', result.data.openid)
					// 		uni.setStorageSync('session_key', result.data.session_key)
					// 	},
					// 	fail: err => {
					// 		// uni.showToast({
					// 		// 	icon: 'none',
					// 		// 	title: err.errMsg
					// 		// })
					// 	} //失败

					// });
					let param = {
						js_code: code
					}
					getOpenid(param).then(res => {
						console.log('获取openid----通过后端接口')
						console.log(res)
						console.log(res.openid)
						console.log(res.session_key)
						uni.setStorageSync('openid', res.openid)
						uni.setStorageSync('session_key', res.session_key)
					})
				}
			})
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	@font-face {
		font-family: 'AvantGardeFont';
		/* 定义你的字体名称 */
		src: url('/static/fonts/AvantGarde-Book.otf') format('truetype');
		/* 指定字体文件的路径和格式 */
	}

	/*每个页面公共css */
	.flex {
		display: flex;
		align-items: center;
	}

	.flex_between {
		justify-content: space-between;
	}

	image {
		will-change: transform; //解决加载时瞬间拉伸问题
		width: auto; //解决加载时瞬间拉伸问题
		height: auto; //解决加载时瞬间拉伸问题
		image-rendering: -moz-crisp-edges;
		image-rendering: -o-crisp-edges;
		image-rendering: -webkit-optimize-contrast;
		image-rendering: crisp-edges;
		-ms-interpolation-mode: nearest-neighbor;
	}

	.zhezhao {
		background-color: rgba(0, 0, 0, 0.5);
		width: 100%;
		height: 100vh;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 9;
	}

	.tan {
		width: 640rpx;
		height: auto;
		position: fixed;
		top: 50%;
		margin-top: -160rpx;
		margin-left: -320rpx;
		left: 50%;
		background-color: rgba(255, 255, 255, 1);
		z-index: 99;
		border-radius: 20rpx;
		padding: 40rpx;
		box-sizing: border-box;

		.tan_title {
			width: 100%;
			height: 46rpx;
			line-height: 46rpx;
			color: rgba(16, 16, 16, 1);
			text-align: center;
			font-weight: bold;
			margin-bottom: 30rpx;
      color: rgba(16,16,16,1);
      font-size: 32rpx;
		}

		.tan_t {
			width: 100%;
			height: auto;
			margin: 0 auto;
			// margin-top: 30rpx;
			align-items: normal;

			.tan_t1 {
				background-color: rgba(249, 65, 65, 1);
				width: 30rpx;
				height: 30rpx;
				color: #fff;
				border-radius: 50%;
				text-align: center;
				margin-right: 10rpx;
				line-height: 30rpx;
				margin-top: 5rpx;
				font-size: 24rpx;
			}

			.tan_t2 {
				color: rgba(16, 16, 16, 1);
				font-size: 28rpx;
				width: 90%;
			}

			.tan_input {
				width: 100%;
				height: 88rpx;
				line-height: 405px;
				border-radius: 10rpx;
				background-color: rgba(238, 238, 238, 1);
				color: rgba(136, 136, 136, 1);
				font-size: 28rpx;
				text-align: left;
				line-height: 88rpx;
				padding: 0 20rpx;
				box-sizing: border-box;
			}
		}

		.tan_b {
			margin-top: 50rpx;

			.tan_b_d1 {
				width: 260rpx;
				height: 72rpx;
				border-radius: 50rpx;
				background-color: rgba(238, 238, 238, 1);
				line-height: 72rpx;
				text-align: center;
				color: rgba(16, 16, 16, 1);
				font-size: 28rpx;
			}

			.tan_b_d2 {
				width: 260rpx;
				height: 72rpx;
				border-radius: 50rpx;
				background-color: #F9BF41;
				line-height: 72rpx;
				text-align: center;
				color: rgba(16, 16, 16, 1);
				font-size: 28rpx;
			}
		}
	}

	.con {
		width: 100%;
		min-height: 100vh;
		background: #eee;
		padding: 30rpx;
		box-sizing: border-box;
	}

	.bg_balck {
		width: 100%;
		height: 300rpx;
		border-radius: 0px 0px 50px 50px;
		background-color: rgba(0, 0, 0, 1);
		color: rgba(16, 16, 16, 1);
		position: fixed;
		top: 0;
		left: 0;
	}

	.tan_newli_wrap {
		width: 100%;
		box-sizing: border-box;
		padding: 0 20rpx;

		.tan_newli {
			width: 100%;
			align-items: normal;
			margin-bottom: 15rpx;

			.tan_newli_img {
				width: 32rpx;
				height: auto;
				margin-right: 6rpx;
				margin-top: 6rpx;
			}

			.tan_newli_v {
				line-height: 40rpx;
				color: rgba(0, 0, 0, 1);
				font-size: 28rpx;
				width: 500rpx;
			}
		}

		.tan_newli:last-child {
			margin-bottom: 0;
		}
	}

	.tan.tan_wen {
		margin-top: -275rpx;
	}

	.tan_wen .tan_b_d2 {
		width: 100% !important;
	}

	.shangXiaCenter {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}
  .topssss{
    width: 100%;
    height: auto;
    text-align: center;
    position: relative;
    margin-bottom: 30rpx;
    .topssss_img{
      position: absolute;
      width: 44rpx;
      height: auto;
      left: 0;
      top:0;
    }
  }
</style>